#include <iostream>
#include <vector>
#include <algorithm>
// #include <utility>
using namespace std;
typedef pair<int, int> PII;
vector<PII> a;
bool compare(PII& x, PII& y) {
    return x.second < y.second;
}
int main() 
{
    int n;
    cin >> n;
    while(n--) {
        int x, y;
        cin >> x >> y;
        a.push_back(make_pair(x, y));
    }
    sort(a.begin(), a.end(), compare);
    int last = a[0].second;
    int ret = 1;
    for(int i = 1; i < a.size(); i++) {
        if(a[i].first >= last) {
            last = a[i].second;
            ret++;
        }
    }
    cout << ret << endl;
    return 0;
}